package organization

import (
	"MembershipRegist/db"
	"MembershipRegist/models"
)

// todo: 活动评论
func (c *Controller) ActivityCommentReplay() {
	commentID, err := c.GetInt("comment_id")
	if err != nil {
		c.ResponseFailed(201, "comment_id 不合法")
		return
	}

	replay := c.GetString("replay")
	if replay == "" {
		c.ResponseFailed(202, "回复内容不能为空")
		return
	}

	var commentValue models.OrganizationActivityComment
	if value := db.DB.Where("id = ?", commentID).First(&commentValue); value.Error != nil {
		c.ResponseFailed(203, "无此评论")
		return
	}

	if commentValue.OrganizationAdminID != 0 {
		c.ResponseFailed(204, "此评论已回复")
		return
	}

	db.DB.Model(&models.OrganizationActivityComment{}).
		Where("id = ?", commentID).Updates(map[string]interface{}{
		"organization_admin_id": c.OrganizationAdminID,
		"replay":                replay,
	})

	c.ResponseSuccess()
}

func (c *Controller) ActivityCommentDelete() {
	commentID, err := c.GetInt("comment_id")
	if err != nil {
		c.ResponseFailed(201, "comment_id 不合法")
		return
	}
	db.DB.Delete(&models.OrganizationActivityComment{}, "id = ?", commentID)

	c.ResponseSuccess()
}
